<?php


class Renderer
{
    static public $codepage = "UTF-8";
    static public $content_type = "text/html";

    static public $codepagesended = false; //FFFFUUUUUUUU
    
    static public $var = array();
    static public $styles = array();
    static public $scripts = array();

    static function RegisterVariable($varname, $varval)
    {
        Renderer::$var[$varname] = $varval;
    }

    static function RegisterVariableByRef($varname, &$varval)
    {
        Renderer::$var[$varname] = $varval;
    }

    static function RegisterStyle($stylename)
    {
        Renderer::$styles[$stylename] = DATA_FOLDER.STYLES_FOLDER.$stylename;
    }

    static function RegisterScript($scriptname)
    {
        Renderer::$scripts[$scriptname] = DATA_FOLDER.SCRIPTS_FOLDER.$scriptname;
    }

    static public function SendCodepage()
    {
        if(!Renderer::$codepagesended)
        {
            header("Content-Type: ".Renderer::$content_type."; charset=".Renderer::$codepage);
            Renderer::$codepagesended = true;
        }
    }


    static public function RenderToString($template)
    {
        if (is_file($template))
        {
            ob_start();
            include $template;
            $contents = ob_get_contents();
            ob_end_clean();
            return $contents;
        }
        return false;
    }

    static public function Render($template, $tostring = false)
    {
        Renderer::SendCodepage();
        $template = Context::$request["rootdir"].DIR_SEPARATOR.TEMPLATES_FOLDER.$template;
        if($tostring)
        {
            return RenderToString($template);
        } else
            include $template;

    }
};

?>
